<template>
  <div class="setting-shan-container">
    <div class="applet-blendent-header">设置新人专享</div>
    <el-form :model="configData" label-width="170px" size="small" style="margin: 20px auto">
      <el-form-item label="开启新人专享" class="goods-form-item">
        <el-switch v-model="configData.is_recruits" active-color="#13ce66" 
          active-value="1" inactive-value="0" @change="submit({is_recruits: configData.is_recruits})"></el-switch>
        <div class="goods-form-item-text" style="width:calc(100% - 150px)">
          若开启新人专享，则需要选择新人专享的商品，此商品只有没有下过单的新用户才能购买。新用户为没有下单支付成功的用户
        </div> 
      </el-form-item>
      <el-form-item label="新用户展示" class="goods-form-item">
        <el-switch v-model="configData.is_recruits_show" active-color="#13ce66" 
          active-value="1" inactive-value="0" @change="submit({is_recruits_show: configData.is_recruits_show})"></el-switch>
        <div class="goods-form-item-text" style="width:calc(100% - 150px)">
          如不开启，则所有用户都可以看到，但不能购买，仅限新用户购买
        </div> 
      </el-form-item>
    </el-form>

    <div>
      <addgoods/>
    </div>
    <!-- <div style="text-align:center;margin-top:15px">
      <el-button type="primary" size="small" style="padding:8px 30px;">提 交</el-button>
    </div> -->
  </div>
</template>

<script>
import { getCutConfig, putRecruitsConfig } from '@/api/marketing'
import addgoods from './components/addgoods'

export default {
  name: 'setting-shansong',
  components: {
    addgoods
  },
  data() {
    return {
      configData: { },
    }
  },
  mounted() {
    this.getCutConfig();
  },
  methods: {
    /**
     * 获取砍价配置
     */
    getCutConfig() {
      getCutConfig({
        id: this.$store.state.app.activeApp.saa_id,
        key: this.$store.state.app.activeApp.saa_key,
      }).then(res => {
        if(res.status === 200) {
          this.configData = res.data;
        }else{
          this.$message.error(res.message);
        }
      })
    },
    submit(status) {
      const params = {
        id: this.$store.state.app.activeApp.saa_id,
        key: this.$store.state.app.activeApp.saa_key,
        ...status
      }
      putRecruitsConfig(params).then(res => {
        if(res.status === 200) {
          this.$message.success('修改成功！');
        }else{
          this.$message.error(res.message);
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.setting-shan-container{
  min-height: calc(100vh - 100px);
  margin: 20px;
  background-color: #fff;
  padding:25px;
  box-shadow: 0px 0px 4px 0px rgba(115, 115, 115, 0.2);
}
.applet-blendent-header{
  height: 40px;
  width: 100%;
  line-height: 40px;
  font-size: 16px; 
  font-weight: 600;
  letter-spacing: 2px;
  color: #8f8f8f;
  padding: 0 10px;
  background-color: #F4F8FB;
}
.goods-form-item{
  width: 100%;
  height: 50px;
  line-height: 50px;
  padding: 5px 0;
  box-sizing: border-box;
  &-input{
    width: 50%;
    height: 40px;
    line-height: 40px;
  }
  &-text{
    width: calc(50% - 100px);
    display: inline-block;
    height: 40px;
    line-height: 40px;
    padding: 0 0 0 20px;
    color: #c0c4cc;
    font-size: 14px;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
    vertical-align: middle;
  }
  &-button-text{
    width: calc(100% - 200px);
    display: inline-block;
    height: 40px;
    line-height: 40px;
    padding: 0 0 0 20px;
    color: #c0c4cc;
    font-size: 14px;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
    vertical-align: middle;
  }
  &-button{
    padding: 5px 10px;
    margin-left: 10px;
  }
  &-video{
    height: 150px;
    min-width: 200px;
    max-width: 100%;
  }
}
</style>